<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组转换为字符串</title>
</head>
<body>
    <script>
        // 将数组  ['关羽', '张飞', '程咬金','吕布']  转换为字符串

        var arr = ['关羽', '张飞', '程咬金','吕布']
        let result = '[';
        for (let i = 0; i < arr.length; i++){
            // console.log(arr[i]);
            // result = result + '\'' + arr[i] + '\'' + ', ';
            // console.log(result)
            if(i == arr.length - 1){
                result = result + '\'' + arr[i] + '\'';
            }else{
                result = result + '\'' + arr[i] + '\'' + ', ';
            }
        }
        result = result + ']';
        console.log(result);
        
    </script>
</body>
</html>